﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using AimGameEngine.EditorObject;

using AimGameLibrary;
using AimGameLibrary.GameObject;

namespace AimGameEngine.NodeEditorObject
{
    public class NodeScreenControl : NodeBaseControl
    {
        public List<String> ListNameScreen;
        public String NameNextScreen;
        public Boolean LoadingIsSlow;

        public NodeScreenControl(SpriteBatch inputspritebatch, Camera inputcamera, NodeData inputData
            , List<IDraw> MyListDraw, List<IUpdateMainTime> MyListUpdateTime, Dictionary<String, NodeObject> MyListObject, Dictionary<String, NodeObject> MyListType)
            : base(inputspritebatch, inputcamera, inputData, MyListDraw,MyListUpdateTime, MyListObject, MyListType)
        {
            NameNextScreen = "NULL";
            ListNameScreen = new List<string>();
            LoadingIsSlow = false;

            InputMode = NodeInputMode.AddScreen;

            Connecter inputUpdate = new Connecter(inputspritebatch, inputcamera, Syco.Output, NodeTypeValue.Update, this);
            ListConnectpoint.Add(inputUpdate);
        }

        public override void ShowProprety(ArrayList Temp, CallBack input)
        {
            base.ShowProprety(Temp, input);
            UpdateScreen();
            PropretyScreenControl propretyscreencontrol = new PropretyScreenControl(this);
            //propretyscreencontrol.Deactivate += new EventHandler(input.Deactivate);
            propretyscreencontrol.okButton.Click += new EventHandler(input.Deactivate);
            propretyscreencontrol.ShowDialog();
            
        }

        void UpdateScreen()
        {
            ListNameScreen.Clear();
            foreach (String keys in MyDictionaryObject.Keys)
            {
                if (MyDictionaryObject[keys].MyData.MyType == NodeTypeValue.Screen)
                    ListNameScreen.Add(keys);
            }
            if (ListNameScreen.Count == 0)
                NameNextScreen = "NULL";
        }

        public override void SaveData(System.Collections.ArrayList Thislist, SaveMode inputsavemode)
        {
            base.SaveData(Thislist,inputsavemode);

            Thislist.Add(InputMode);
            if (InputMode == NodeInputMode.AddScreen)
            {
                Thislist.Add(NameNextScreen);
            }
            else if (InputMode == NodeInputMode.LoadingScreen)
            {
                Thislist.Add(NameNextScreen);
                Thislist.Add(LoadingIsSlow);
            }
        }

        public override void LoadData(Identification getdata, int IndexData)
        {
            base.LoadData(getdata, IndexData);

            if (getdata.Items.GetValue(IndexData + 1).GetType() == typeof(NodeInputMode))
            InputMode = (NodeInputMode)getdata.Items.GetValue(IndexData + 1);
            if (InputMode == NodeInputMode.AddScreen)
            {
                if (getdata.Items.GetValue(IndexData + 2).GetType() == typeof(NodeInputMode))
                NameNextScreen = (String)getdata.Items.GetValue(IndexData + 2);
            }
            else if (InputMode == NodeInputMode.LoadingScreen)
            {
                if (getdata.Items.GetValue(IndexData + 2).GetType() == typeof(NodeInputMode))
                NameNextScreen = (String)getdata.Items.GetValue(IndexData + 2);
                if (getdata.Items.GetValue(IndexData + 3).GetType() == typeof(NodeInputMode))
                LoadingIsSlow = (Boolean)getdata.Items.GetValue(IndexData + 3);
            }
        }
    }
}
